{% extends 'template.html' %}
{% load staticfiles %}

{% block username %}
    {{ request.user.username }}
{% endblock %}

{% block content %}
    <div id="page-wrapper">
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">配置修改记录-{{ task_config }}</h1>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <div class="btn-group">
                            <a href="/assets/system_cron_list/" class="btn btn-success">返回</a>
                        </div>
                    </div>
                    <div class="panel-body">
                        {% if history %}
                            <table id="mytable" width="100%" cellspacing="0"
                                   class="table table-striped table-hover">
                                <thead>
                                <tr>
                                    <th>任务名称</th>
                                    <th>配置文件名</th>
                                    <th>类型</th>
                                    <th>修改时间</th>
                                    <th>修改人</th>
                                    <th>备注</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                {% for h in history %}
                                    <tr>
                                        <td>{{ h.salt_config.salt_task.name }}</td>
                                        <td>{{ h.salt_config.filename }}</td>
                                        <td>{{ h.get_type_display }}</td>
                                        <td>{{ h.modified_time|date:"Y-m-d H:i:s" }}</td>
                                        <td>{{ h.modified_user.username }}</td>
                                        <td>{% if h.remark %}{{ h.remark }}{% else %}{% endif %}</td>
                                        <td>
                                            <button class="btn btn-sm btn-danger" onclick="view_detail({{ h.id }})">查看详情并回滚
                                            </button>
                                        </td>
                                    </tr>
                                {% endfor %}
                                </tbody>
                            </table>
                        {% else %}
                            <p>还没有修改记录！</p>
                        {% endif %}
                    </div>
                </div>
            </div>


            <!-- Modal-->
            <div class="modal fade" id="Modal-edit" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:1000px;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title" id="myModalLabel">修改详情</h4>
                        </div>
                        <form method="POST" action="/assets/history_recover/">
                            <div class="modal-body" style="height:750px;overflow:auto;">
                                <input type="text" style="display: none" id="history_id" name="history_id" value="">
                                <div class="form-group row">
                                    <label class="control-label col-md-2">任务名称</label>
                                    <div class="col-md-5">
                                        <span id="task_name" value=""></span>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">配置文件名</label>
                                    <div class="col-md-5">
                                        <span id="filename" value=""></span>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">修改原因备注</label>
                                    <div class="col-md-9">
                                      <textarea readonly class="form-control" rows="3" cols="100" id="remark"
                                                value="remark" value=""></textarea>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">修改内容</label>
                                    <div class="col-md-9">
                                      <textarea readonly class="form-control" rows="30" cols="100" id="content"
                                                value="content" value=""></textarea>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label class="control-label col-md-2">回滚原因备注</label>
                                    <div class="col-md-9">
                                      <textarea class="form-control" rows="3" cols="100" id="recover_remark"
                                                name="recover_remark" placeholder="请填写回滚原因（可选）！"></textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="submit" class="btn btn-danger" name='action'>回滚</button>
                            </div>
                        </form>
                    </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->
            </div>
            <div id="is_superuser" data-is-superuser="{{ is_superuser }}"></div>

        </div>
    </div>
{% endblock %}
{% block bodyjs %}
    <script src="/static/js/jquery.dataTables.min.js"></script>
    <script src="/static/js/salt_config_history.js?v=sdf9htnjf12341jtkdfgdsh01jtgng0sf"></script>
    <script src="/static/js/dataTables.colVis.js"></script>
{% endblock %}
{% block css %}
    <link href="/static/css/jquery.dataTables.css" rel="stylesheet" type="text/css">
    <link href="/static/css/dataTables.colVis.css" rel="stylesheet" type="text/css">
{% endblock %}
